package com.iakuil.app.common.core.exception;

import com.iakuil.app.common.core.enums.Results;

/**
 * 异常基础类
 *
 * <p>所有自定义异常都必须定义错误码code属性。
 * <p>被{@code GlobalExceptionHandler}捕获后统一处理。
 *
 * @author Kai
 */
public abstract class BaseException extends RuntimeException {

    private int code;

    public BaseException() {
        // 默认错误码500
        super(Results.INTERNAL_SERVER_ERROR.getMessage());
    }

    public BaseException(int code) {
        this.code = code;
    }

    public BaseException(String message) {
        super(message);
    }

    public BaseException(int code, String message) {
        super(message);
        this.code = code;
    }

    public BaseException(int code, String message, Throwable cause) {
        super(message, cause);
        this.code = code;
    }

    public BaseException(int code, Throwable cause) {
        super(cause);
        this.code = code;
    }

    public BaseException(String message, Throwable cause) {
        super(message, cause);
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }
}
